import type { ProgressInfo } from "electron-updater";

export interface IpcMainEventListener<Send = void, Receive = void> {
  ipcMainHandle: Send extends void
    ? (event: Electron.IpcMainInvokeEvent) => Receive | Promise<Receive>
    : (
        event: Electron.IpcMainInvokeEvent,
        args: Send
      ) => Receive | Promise<Receive>;
  ipcRendererInvoke: Send extends void
    ? () => Promise<Receive>
    : (args: Send) => Promise<Receive>;
}

export interface IpcRendererEventListener<Send = void> {
  webContentSend: Send extends void
    ? (webContents: Electron.WebContents) => void
    : (webContents: Electron.WebContents, args: Send) => void;

  ipcRendererOn: Send extends void
    ? (event: Electron.IpcRendererEvent) => void
    : (event: Electron.IpcRendererEvent, args: Send) => void;
}

export class IpcChannelMainClass {
  /**
   * 退出应用
   */
  AppClose: IpcMainEventListener = null;
  CheckUpdate: IpcMainEventListener = null;
  ConfirmUpdate: IpcMainEventListener = null;
  DownloadUpdate: IpcMainEventListener = null;
}

export class IpcChannelRendererClass {
  UpdateMsg: IpcRendererEventListener<{
    state: number;
    msg: string | ProgressInfo;
  }> = null;

  DownloadProBar: IpcRendererEventListener<{
    percent: number;
    bytesPerSecond: number;
  }> = null;
}
